//
//  ZYLFindFrontCollectionViewCell.m
//  Cartoon
//
//  Created by dllo on 15/7/13.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "ZYLFindFrontCollectionViewCell.h"
#import "Define.h"
#import "UIImageView+WebCache.h"
@implementation ZYLFindFrontCollectionViewCell

- (void)dealloc
{
    [_title release];
    [_name release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.mainImage = [[[UIImageView alloc] init] autorelease];
        self.mainImage.backgroundColor = [UIColor greenColor];
        [self.contentView addSubview:self.mainImage];
        
        self.blackView = [[[UIView alloc] init] autorelease];
        [self.mainImage addSubview:self.blackView];
        
        self.backView = [[[UIView alloc] init] autorelease];
        [self.mainImage addSubview:self.backView];
        
        self.title = [[[UILabel alloc] init] autorelease];
        [self.backView addSubview:self.title];
        
        self.name = [[[UILabel alloc] init] autorelease];
        [self.backView addSubview:self.name];
        
        self.gradientLayer = [CAGradientLayer layer];
        [self.blackView.layer insertSublayer:self.gradientLayer atIndex:0];
    }
    return self;
}

- (void)setTopicModel:(ZYLSearchResultModel *)topicModel
{
    if (_topicModel != topicModel) {
        [_topicModel release];
        _topicModel = [topicModel retain];
    }
    [self.mainImage sd_setImageWithURL:[NSURL URLWithString:topicModel.searchvertical_image_url]];
    self.title.text = topicModel.searchtitle;
    self.name.text = topicModel.searchnickname;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    self.mainImage.frame = CGRectMake(0, 0, layoutAttributes.size.width, layoutAttributes.size.height);
    self.backView.frame = CGRectMake(0, layoutAttributes.size.height / 5 * 4, layoutAttributes.size.width, layoutAttributes.size.height / 5);
    self.title.frame = CGRectMake(0, 0, self.backView.frame.size.width, self.backView.frame.size.height / 2);
    self.name.frame = CGRectMake(0, self.backView.frame.size.height / 2, self.backView.frame.size.width, self.backView.frame.size.height / 2);
    self.title.textColor = [UIColor whiteColor];
    self.name.textColor = [UIColor whiteColor];
    
    self.blackView.frame = CGRectMake(0, 0, layoutAttributes.size.width, layoutAttributes.size.height);
    self.gradientLayer.frame = self.blackView.bounds;
    self.gradientLayer.colors = [NSArray arrayWithObjects:
                                 (id)[[UIColor clearColor] CGColor],
                                 (id)[[UIColor blackColor] CGColor], nil];
    self.gradientLayer.startPoint = CGPointMake(0.5, 0.5);
    self.gradientLayer.endPoint = CGPointMake(0.5, 1.0);
    
}
@end
